<?php
/**
 * 前台网站风格 控制器
 *
 */
class StyleAction extends Action
{
	/**
	 * 网站统一配置
	 *
	 * @var unknown_type
	 */
	public $Config;
	
	/**
	 * 构造函数
	 *
	 */
	public function _initialize()
	{
		$Config = D('Config');
		$this->Config = $Config->find('config_id=1');
	}
	/**
	 * 管理风格
	 */
	public function UserIndex()
	{
		EasyACL('Style','UserIndex',$_SESSION);
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		if ($_SESSION['Q'] != 'Administrator') {
			$conditions->put($_SESSION['Q'],array('EQ','Y'));
		} else {
			$conditions = '';
		}
		$Style = D('Style');
		$count = $Style->count($conditions,'sid');
		$listRows = 12;
		$fields = 'sid,name,style_path,simg';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Style->findall($conditions,$fields,'sid desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		
		//To Templates
		$this->assign('Style',$list);
		$this->assign('page',$page);
		$this->assign('Config',$this->Config);
		$this->display();
	}
	
	/**
	 * 设置风格
	 */
	public function UserSetStyle()
	{
		EasyACL('Style','UserSetStyle',$_SESSION);
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$_SESSION['enter_id']));
		
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		
		$Enterprise = D('Enterprise');
		$Enterprise->where($conditions)->find();
		$Enterprise->templates = $Input->get('style_path');
		if ($Enterprise->save()) {
			return $this->success('设置成功!');
		} else {
			return $this->error('设置风格失败');
		}
	}
}
?>





